package com.element.music.controller;

import com.element.music.component.cofig.BaseResponse;
import com.element.music.controller.query.collection.CollectionDescriptionQueryDTO;
import com.element.music.controller.query.collection.CollectionOpenSeaQueryDTO;
import com.element.music.controller.query.collection.CollectionTwitterQueryDTO;
import com.element.music.controller.query.collection.CollectionWebsiteQueryDTO;
import com.element.music.controller.vo.CollectionIdVO;
import com.element.music.service.CollectionService;
import com.element.music.service.dto.CollectionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能描述： collection 收藏夹控制器
 * <p>
 * User: nft musician developer
 * Date: 2022/1/10
 */

@RestController
@RequestMapping("collection")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    private static BaseResponse successResponse() {
        return BaseResponse.of().setCode(0).setMsg("edit collection information successfully");
    }

    @PostMapping("add")
    public BaseResponse addCollection(@RequestParam("contractAddress") String contractAddress) {
        CollectionIdVO collectionIdVO = collectionService.addCollection(contractAddress);
        return BaseResponse.of().setCode(0).setMsg("create collection successfully").setData(collectionIdVO);
    }

    @PostMapping("edit/description")
    public BaseResponse editCollectionDescription(@RequestBody CollectionDescriptionQueryDTO
                                                              collectionDescriptionQueryDTO) {
        collectionService.updateCollectionDescription(collectionDescriptionQueryDTO.getCollectionId(),
                collectionDescriptionQueryDTO.getDescription());
        return successResponse();
    }

    @PostMapping("edit/website")
    public BaseResponse editCollectionWebsite(@RequestBody CollectionWebsiteQueryDTO collectionWebsiteQueryDTO) {
        collectionService.updateCollectionWebsite(collectionWebsiteQueryDTO.getCollectionId(),
                collectionWebsiteQueryDTO.getWebsite());
        return successResponse();
    }

    @PostMapping("edit/twitter")
    public BaseResponse editCollectionTwitter(@RequestBody CollectionTwitterQueryDTO collectionTwitterQueryDTO) {
        collectionService.updateCollectionTwitter(collectionTwitterQueryDTO.getCollectionId(),
                collectionTwitterQueryDTO.getTwitter());
        return successResponse();
    }

    @PostMapping("edit/opensea")
    public BaseResponse editCollectionOpenSea(@RequestBody CollectionOpenSeaQueryDTO collectionOpenSeaQueryDTO) {
        collectionService.updateCollectionOpenSea(collectionOpenSeaQueryDTO.getCollectionId(),
                collectionOpenSeaQueryDTO.getOpensea());
        return successResponse();
    }

    @GetMapping("view/contract-address")
    public BaseResponse getCollectionByContractAddress(@RequestParam("contractAddress") String contractAddress) {
        CollectionDTO collectionDTO = collectionService.getCollectionByContractAddress(contractAddress);
        return BaseResponse.of().setCode(0).setMsg("view collection information successfully").setData(collectionDTO);
    }

    @GetMapping("view/id")
    public BaseResponse getCollectionById(@RequestParam("id") Long id) {
        CollectionDTO collectionDTO = collectionService.getCollectionById(id);
        return BaseResponse.of().setCode(0).setMsg("view collection information successfully").setData(collectionDTO);
    }

    @GetMapping("list")
    public BaseResponse getCollectionList() {
        List<CollectionDTO> collectionDTOList = collectionService.getCollectionList();
        return BaseResponse.of().setCode(0).setMsg("list user successfully").setData(collectionDTOList);
    }

    @DeleteMapping("delete")
    public BaseResponse delCollection(@RequestParam("contractAddress") String contractAddress) {
        collectionService.delCollectionByContractAddress(contractAddress);
        return BaseResponse.of().setCode(0).setMsg("delete collection successfully");
    }


}
